// MobileTV global configure header file.
//
// Description:
//  1, shielding the differeces in all compatible platforms.
//  2, defining stored path of all data.
//  3, other global definitions.
//



#ifndef MOBILE_TV_CONFIG_H
#define MOBILE_TV_CONFIG_H

#if __GNUC__ > 3 || _MSC_VER > 1020
#pragma once
#endif

#ifndef __cplusplus
#error this header requires C++ compiler
#endif

#include "stdio.h"
#include <stdlib.h>
#include <string.h>

#include "alog.h"

extern "C++"
{
#ifndef OS_TD
#define OS_TD
//#include "sharingx.h"
#include "STL/STL_list.h"
#include "STL/STL_string.h"
#include "STL/STL_vector.h"
#undef OS_TD
#endif


#define INDEX(n) [n]
#define VECTOR vector
#define LIST list

}

//#include <string.h>

extern "C" void* mmicmmb2_MemAlloc(int size);
extern "C" void mmicmmb2_MemFree(void* pMemToFree);
extern "C" void* mmicmmb2_MemRealloc(void *ptr, unsigned int size);


#if 0  //liwk 2010/2/10
static void mbbmsFree(void *ptr)
{
    if (ptr)
        freeAL(ptr);
}
#endif  //#if 0 liwk 2010/2/10

#define mbbmsFree(ptr)       if (ptr) mmicmmb2_MemFree(ptr);\
    ptr=NULL;

#if 1
static void *mbbmsMalloc(size_t size)
{
    void *buf;
    //MBBMS_LOGD("in mbbmsMalloc, size is %d", size);
    buf = mmicmmb2_MemAlloc(size);

    //MBBMS_LOGD("in mbbmsMalloc, buf is %x", buf);
    return buf;
}
#endif

#define malloc mmicmmb2_MemAlloc
#define realloc mmicmmb2_MemRealloc
#define free   mmicmmb2_MemFree

extern "C" int strcasecmp(const char *s1, const char *s2);
extern "C" int strncasecmp(const char *s1, const char *s2, size_t n);
extern "C" size_t strlen(const char *s);
extern "C" char *strcpy(char *dst, const char *src);
//extern "C" char *strstr(char *s1, char *s2);
inline char *strdup(const char *src)
{
    char *dst;

    if (!src)
        return NULL;

    size_t len = strlen(src);

    dst = (char *)mmicmmb2_MemAlloc(len + 1);

    if (!dst)
        return NULL;

    strcpy(dst, src);

    return dst;
}

typedef unsigned char uint8_t;
typedef unsigned int size_t;

// for memory usage test
extern "C" unsigned long MaxHole(void);
extern "C" unsigned long MaxHole1(void);
#ifdef T3G_BIG_ENDIAN
typedef struct
{
    int hi;
    unsigned int lo;
} int64_t;
#else
typedef struct
{
    unsigned int lo;
    int hi;
} int64_t;
#endif


#if 0  //liwk 2009/11/16
#ifdef WINCE
#define strcasecmp(a, b) _stricmp(a, b)
#define strncasecmp(a, b, n) _strnicmp(a, b, n)
#define snprintf _snprintf
#define strdup(a) _strdup(a)

#define mktime(a) MkTime(a)
#define localtime(a) LocalTime(a)
#define time(a) Time(a)

typedef __int64 int64_t;
typedef unsigned char uint8_t;

#elif defined(WIN32)
#define strcasecmp(a, b) _stricmp(a, b)
#define strncasecmp(a, b, n) _strnicmp(a, b, n)
#define snprintf _snprintf
#define strdup(a) _strdup(a)

#elif defined(T3G)
#include <string.h>

extern "C" void *mallocAL(size_t size);
extern "C" void freeAL(void *ptr);
extern "C" void *reallocAL(void *ptr, size_t size);

static void mbbmsFree(void *ptr)
{
    if (ptr)
        freeAL(ptr);
}

#if 0
static void *mbbmsMalloc(size_t size)
{
    void *buf;
    MBBMS_LOGD("in mbbmsMalloc, size is %d", size);
    buf = mallocAL(size);

    MBBMS_LOGD("in mbbmsMalloc, buf is %x", buf);
    return buf;
}
#endif
#define malloc mallocAL
#define realloc reallocAL
#define free   mbbmsFree

extern "C" int strcasecmp(const char *s1, const char *s2);
extern "C" int strncasecmp(const char *s1, const char *s2, size_t n);
extern "C" size_t strlen(const char *s);
extern "C" char *strcpy(char *dst, const char *src);
//extern "C" char *strstr(char *s1, char *s2);
inline char *strdup(const char *src)
{
    char *dst;

    if (!src)
        return NULL;

    size_t len = strlen(src);

    dst = (char *)malloc(len + 1);

    if (!dst)
        return NULL;

    strcpy(dst, src);

    return dst;
}

typedef unsigned char uint8_t;
typedef unsigned int size_t;

// for memory usage test
extern "C" unsigned long MaxHole(void);
extern "C" unsigned long MaxHole1(void);
#ifdef T3G_BIG_ENDIAN
typedef struct
{
    int hi;
    unsigned int lo;
} int64_t;
#else
typedef struct
{
    unsigned int lo;
    int hi;
} int64_t;
#endif


#else
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#endif


#ifdef USE_ANDROID_STL
#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/List.h>
using namespace android;

#define INDEX(n) .editItemAt(n)
#define VECTOR android::Vector
#define LIST android::List
#define push_back(i) push(i)
#define pop_back(i) pop(i)
#define c_str(i) string(i)

typedef String8 string;

#elif defined(USE_INNER_STL)
#include "astring.h"
#include "avector.h"
#include "alist.h"

#define INDEX(n) [n]
#define VECTOR vector
#define LIST list

#elif defined(USE_USTL)
#include "ustl.h"
#include "ustring.h"
#include "uvector.h"
#include "ulist.h"
using namespace ustl;

#define INDEX(n) [n]
#define VECTOR vector
#undef LIST
#define LIST list
#elif defined(STL_T3G)
#include "STL/STL_list.h"
#include "STL/STL_string.h"
#include "STL/STL_vector.h"

#define INDEX(n) [n]
#define VECTOR vector
#define LIST list
#else
#include <string>
#include <vector>
#include <list>
using namespace std;

#define INDEX(n) [n]
#define VECTOR vector
#define LIST list
#endif
#endif  //#if 0 liwk 2009/11/13


#endif

